package tk.mybatis.springboot.model;

import java.io.Serializable;

import tk.mybatis.springboot.share.util.DateUtils;
import tk.mybatis.springboot.wexin.enums.MessageStateEnum;

public class Message implements Serializable {

	private static final long serialVersionUID = -7575041938552426008L;

	/**
	 * 状态
	 */
	private MessageStateEnum code;

	/**
	 * 信息
	 */
	private String message;

	/**
	 * 时间
	 */
	private String time;

	/**
	 * 数据
	 */
	private Object data;

	public Message(MessageStateEnum code, String message, String time) {
		super();
		this.code = code;
		this.message = message;
		this.time = time;
	}

	/**
	 * 返回成功信息
	 * 
	 * @param data
	 * @return
	 */
	public static Message success() {
		Message msg = new Message(MessageStateEnum.success, "获取数据成功", DateUtils.getNowTime_6());
		return msg;
	}

	/**
	 * 返回固定消息的成功信息
	 * 
	 * @param data
	 * @return
	 */
	public static Message success(Object data) {
		Message msg = new Message(MessageStateEnum.success, "获取数据成功", DateUtils.getNowTime_6());
		msg.setData(data);
		return msg;
	}

	/**
	 * 展示成功信息，包含数据
	 * 
	 * @param message
	 * @param data
	 * @return
	 */
	public static Message success(String message, Object data) {
		Message msg = new Message(MessageStateEnum.success, message, DateUtils.getNowTime_6());
		msg.setData(data);
		return msg;
	}

	/**
	 * 失败的信息及通用数据
	 * @param message
	 * @param data
	 * @return
	 */
	public static Message fail(String message, Object data) {
		Message msg = new Message(MessageStateEnum.fail, message, DateUtils.getNowTime_6());
		msg.setData(data);
		return msg;
	}

	/**
	 * 返回失败信息和失败原因
	 * 
	 * @param message
	 * @return
	 */
	public static Message fail(String message) {
		return new Message(MessageStateEnum.fail, message, DateUtils.getNowTime_6());
	}

	/**
	 * 返回错误信息和错误原因
	 * 
	 * @param message
	 * @return
	 */
	public static Message error(String message) {
		return new Message(MessageStateEnum.error, message, DateUtils.getNowTime_6());
	}

	/**
	 * 返回固定信息的错误
	 *
	 * @return
	 */
	public static Message error() {
		return new Message(MessageStateEnum.error, "服务器错误，我们已记录并将尽快处理", DateUtils.getNowTime_6());
	}

	/**
	 * 成功后的消息
	 * @return
	 */
	public static Message wsuccess(String message) {
		return new Message(MessageStateEnum.success, message, DateUtils.getNowTime_6());
	}

	public MessageStateEnum getCode() {
		return code;
	}

	public void setCode(MessageStateEnum code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

}

